package com.russell.pms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.russell.pms.ExceptionCode;
import com.russell.pms.dao.PropertyDao;
import com.russell.pms.exception.PMSException;
import com.russell.pms.model.Property;
import com.russell.pms.service.PropertyService;

@Service("propertyService")
@Transactional(readOnly = true)
public class PropertyServiceImpl extends BaseService implements PropertyService {
	@Autowired
	private PropertyDao propertyDao;

	public void setPropertyDao(PropertyDao propertyDao) {
		this.propertyDao = propertyDao;
	}

	public Property getProperty(int propId) {
		Property property = propertyDao.getProperty(propId);
		if (property == null) {
			throw new PMSException(ExceptionCode.PROPERTY_NOT_FOUND);
		}

		return property;
	}

	public List<Property> getProperties() {
		return propertyDao.getProperties();

	}

	@Transactional(value = "pms", readOnly = false, propagation = Propagation.REQUIRES_NEW, rollbackFor = java.lang.Exception.class)
	public void removeProperty(int propId) throws Exception {
		Property property = propertyDao.getProperty(propId);
		if (property == null) {
			throw new PMSException(ExceptionCode.PROPERTY_NOT_FOUND);
		}
		propertyDao.removeProperty(property);
	}

	@Transactional(value = "pms", readOnly = false, propagation = Propagation.REQUIRES_NEW, rollbackFor = java.lang.Exception.class)
	public void removeProperty(Property property) throws Exception {
		propertyDao.removeProperty(property);

	}

	@Transactional(value = "pms", readOnly = false, propagation = Propagation.REQUIRES_NEW, rollbackFor = java.lang.Exception.class)
	public void saveProperty(Property property) {
		propertyDao.saveProperty(property);

	}

	@Transactional(value = "pms", readOnly = false, propagation = Propagation.REQUIRES_NEW, rollbackFor = java.lang.Exception.class)
	public void updateProperty(Property property) {
		propertyDao.updateProperty(property);
	}

}
